home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SOURCE.ZIP / BT.ASM < prev    next >
Assembly Source File  |  1987-02-09  |  9KB  |  374 lines

  1.     page    ,132
  2.     title    BootThru  - v1.05
  3.  
  4. ;------------------------------------------------------------------------
  5. ;
  6. ;  BootThru  -    Copyright (c) Bill Gibson - 1987
  7. ;        Lathrup Village, Mi 48076
  8. ;
  9. ;  Ver. 1.00 - Initial version             (not rlsd) -  01/11/87
  10. ;    1.01 - revised code structure              "     -  01/25/87
  11. ;    1.02 - revised Modify Proc              "     -  02/01/87
  12. ;    1.03 - enhanced error message output          "     -  02/06/87
  13. ;    1.04 - revised Print Proc          released  -  02/07/87
  14. ;    1.05 - fix incompatibility plbm             -  02/09/87
  15. ;
  16. ;
  17. ;  For Public Domain Use.  Not for Sale or Hire.
  18. ;------------------------------------------------------------------------
  19. COMMENT *
  20.  
  21.       Routine to modify diskette boot record, using drive A: or B:,
  22.       thus circumventing DOS' non-system disk display error.
  23.  
  24.       Usage:
  25.             BT A:       -> transfer new boot record to drive A:
  26.             BT B:       -> transfer new boot record to drive B:
  27.             BT           -> starts program, default is drive A:
  28. *
  29. ;------------------------------------------------------------------------
  30. code        SEGMENT BYTE PUBLIC 'code'
  31. ASSUME        CS:code,DS:code,SS:code
  32.         ORG    5Ch            ;drive id
  33. param1        LABEL    BYTE
  34.         ORG    5Dh            ;elim spurrious characters
  35. param2        LABEL    BYTE
  36.  
  37.         ORG    100h
  38.  
  39. BootThru    PROC    FAR
  40.         MOV    CS:stk_ptr,SP        ;save stack ptr to ensure ret
  41.         CALL    Chk_Ver         ;dos 2.0 or greater
  42.  
  43.         CALL    Scan
  44.         CALL    Dwrite
  45.         JMP    SHORT exit
  46. error:
  47.         MOV    SP,stk_ptr        ;insure proper return
  48.         CALL    Print            ;print error messages
  49.         MOV    AL,1            ;set errorlevel to 1
  50. exit:
  51.         MOV    AH,4Ch
  52.         INT    21h
  53.  
  54. ;------------------------------------------------------------------------
  55. ; Work Area - constants,equates,messages
  56. ;------------------------------------------------------------------------
  57. drive        DB    0
  58. stk_ptr     DW    0
  59.  
  60. blank        EQU    020h        ;ascii space code
  61. cr        EQU    0Dh        ;carriage return
  62. lf        EQU    0Ah        ;line feed
  63. esc        EQU    01Bh        ;escape char
  64. stopper     EQU    255        ;end of display line indicator
  65.  
  66. logo    DB    cr,lf,'BootThru - The Diskette Modifier'
  67.     DB    cr,lf,'Version 1.05 - Bill Gibson 1987',cr,lf,stopper
  68.  
  69. usage    DB    cr,lf,'Usage: BT [drive A: or B:]',cr,lf,stopper
  70. sorry    DB    cr,lf,'Wrong PC DOS Version',cr,lf,stopper
  71. msg1    DB    cr,lf,'Insert diskette in drive A, and press ENTER'
  72.     DB    ' when ready ...',stopper
  73. msg2    DB    cr,lf,'Insert diskette in drive B, and press ENTER'
  74.     DB    ' when ready ...',stopper
  75. msg3    DB    cr,lf,'Press ENTER to modify another disk',cr,lf
  76.     DB    'or ESCape to quit...',stopper
  77. msg4    DB    cr,lf,cr,lf,'Transferring New Boot Sector',cr,lf,stopper
  78. msg5    DB    cr,lf,'Transfer Completed',cr,lf,stopper
  79.  
  80. msg80h    DB    cr,lf,cr,lf,'* Error *  Drive failed to respond.',cr,lf,cr,lf,stopper
  81. msg40h    DB    cr,lf,cr,lf,'* Error *  Seek operation failed.',cr,lf,cr,lf,stopper
  82. msg20h    DB    cr,lf,cr,lf,'* Error *  Controller failure.',cr,lf,cr,lf,stopper
  83. msg10h    DB    cr,lf,cr,lf,'* Error *  Bad CRC on diskette write.',cr,lf,cr,lf,stopper
  84. msg08h    DB    cr,lf,cr,lf,'* Error *  DMA overrun on operation.',cr,lf,cr,lf,stopper
  85. msg04h    DB    cr,lf,cr,lf,'* Error *  Requested sector not found.',cr,lf,cr,lf,stopper
  86. msg03h    DB    cr,lf,cr,lf,'* Error *  Write protected diskette.',cr,lf,cr,lf,stopper
  87. msg02h    DB    cr,lf,cr,lf,'* Error *  Address mark not found.',cr,lf,cr,lf,stopper
  88. msggen    DB    cr,lf,cr,lf,'* Unknown Error *',cr,lf,cr,lf,stopper
  89.  
  90. ;--------------------------------------------------------------------------
  91. ; Sub-Routines:
  92. ;--------------------------------------------------------------------------
  93. Chk_Ver     PROC    NEAR
  94.         MOV    AH,30h        ;verify DOS 2.0 or later
  95.         INT    21h
  96.         CMP    AL,2
  97.         JAE    SHORT chk_ok
  98.         MOV    DX,OFFSET sorry
  99.         JMP    error
  100. chk_ok:
  101.         RET
  102. Chk_Ver     ENDP
  103.  
  104. ;--------------
  105.  
  106. Scan        PROC    NEAR        ;check for any spurrious chars
  107.         MOV    AL,[param2]
  108.         CMP    AL,blank        ;anything ?
  109.         JNZ    shlp            ;yes, give error msg
  110. s1:
  111.         MOV    AL,[param1]    ;check for drive parameters
  112.         OR    AL,AL            ;anything ?
  113.         JNZ    s2            ;jump and test
  114.         MOV    DX,OFFSET logo        ;setup default drive A:
  115.         CALL    Print
  116.         MOV    drive,0
  117.         MOV    DX,OFFSET msg1
  118.         RET
  119. s2:
  120.         CMP    AL,01            ;setup for drive A:
  121.         JZ    SHORT sdrvA
  122.         CMP    AL,02            ;for drive B:
  123.         JZ    SHORT sdrvB
  124. shlp:
  125.         MOV    DX,OFFSET usage     ;display for invalid drives
  126.         JMP    error
  127. sdrvA:
  128.         MOV    DX,OFFSET logo
  129.         CALL    Print
  130.         MOV    drive,0
  131.         MOV    DX,OFFSET msg1
  132.         RET
  133. sdrvB:
  134.         MOV    DX,OFFSET logo
  135.         CALL    Print
  136.         MOV    drive,1
  137.         MOV    DX,OFFSET msg2
  138.         RET
  139.  
  140. Scan        ENDP
  141.  
  142. ;--------------
  143.  
  144. Dwrite        PROC    NEAR        ;transfer new disk boot sector
  145.  
  146.         CALL    Print        ;get ready
  147. d1:
  148.         MOV    AH,8        ;use function 8 in order to detect
  149.         INT    21h        ;ctrl-breaks
  150.         CMP    AL,esc        ;ESC & Ctrl-Break aborts process
  151.         JZ    d5
  152.         CMP    AL,cr
  153.         JNZ    d1
  154. d2:
  155.         MOV    DX,OFFSET msg4        ;setup for disk write
  156.         CALL    Print
  157.         MOV    AL,drive
  158.         LEA    BX,head
  159.         MOV    CX,0001
  160.         MOV    DX,0000
  161. drite:                        ;more setups
  162.         PUSH    AX
  163.         PUSH    BX
  164.         PUSH    CX
  165.         PUSH    DX
  166.         INT    26h
  167.         JC    derror            ;processing error ?
  168.         POPF                ;done
  169.         POP    DX
  170.         POP    CX
  171.         POP    BX
  172.         POP    AX
  173. d3:
  174.         MOV    DX,OFFSET msg5        ;transfer complete
  175.         CALL    Print
  176.         JMP    d4
  177. derror:                     ;display disk errror
  178.         CALL    ErrorList
  179. dend_of:
  180.         CALL    Print
  181.         POPF                ;done
  182.         POP    DX
  183.         POP    CX
  184.         POP    BX
  185.         POP    AX
  186. d4:
  187.         MOV    DX,OFFSET msg3        ;another ?
  188.         CALL    Print
  189.         JMP    d1            ;loop
  190. d5:
  191.         RET
  192. Dwrite        ENDP
  193.  
  194. ;--------------
  195.  
  196. Print        PROC    NEAR        ;a Great idea from Vern Buerg !
  197.         PUSH    SI
  198.         PUSH    BX
  199.         PUSH    CX
  200.         MOV    SI,DX        ;DX has the offset to string
  201.         SUB    CX,CX        ;set to zero for count
  202. p1:
  203.         LODSB
  204.         CMP    AL,stopper    ;string ends in FFh
  205.         JE    p9
  206.         INC    CX        ;increment text length
  207.         JMP    p1
  208. p9:
  209.         MOV    AH,40h        ;write using file handles
  210.         MOV    BX,1
  211.         INT    21h
  212.         POP    CX
  213.         POP    BX        ;recover registers
  214.         POP    SI
  215.         RET
  216. Print        ENDP
  217.  
  218. ;--------------
  219.  
  220. ErrorList    PROC    NEAR        ;error code interpretation
  221.                     ;the upper byte (AH) contains error
  222. err80h:     CMP    AH,080h         ;attachment failed to respond
  223.         JNZ    err40h
  224.         MOV    DX,OFFSET msg80h
  225.         RET
  226. err40h:
  227.         CMP    AH,040h         ;seek operation failed
  228.         JNZ    err20h
  229.         MOV    DX,OFFSET msg40h
  230.         RET
  231. err20h:
  232.         CMP    AH,020h         ;controller failed
  233.         JNZ    err10h
  234.         MOV    DX,OFFSET msg20h
  235.         RET
  236. err10h:
  237.         CMP    AH,010h         ;data error (bad CRC)
  238.         JNZ    err08h
  239.         MOV    DX,OFFSET msg10h
  240.         RET
  241. err08h:
  242.         CMP    AH,08h            ;direct memory access failure
  243.         JNZ    err04h
  244.         MOV    DX,OFFSET msg08h
  245.         RET
  246. err04h:
  247.         CMP    AH,04h            ;requested sector not found
  248.         JNZ    err03h
  249.         MOV    DX,OFFSET msg04h
  250.         RET
  251. err03h:
  252.         CMP    AH,03h            ;write-protect fault
  253.         JNZ    err02h
  254.         MOV    DX,OFFSET msg03h
  255.         RET
  256. err02h:
  257.         CMP    AH,02h            ;bad address mark
  258.         JNZ    errgen
  259.         MOV    DX,OFFSET msg02h
  260.         RET
  261. errgen:
  262.         MOV    DX,OFFSET msggen    ;something new ?  (Unknown)
  263.         RET
  264. ErrorList    ENDP
  265.  
  266. ;--------------
  267.  
  268. Modify        PROC    FAR
  269. head:
  270. cr        EQU    0Dh        ;carriage return
  271. lf        EQU    0Ah        ;line feed
  272. stopper     EQU    255        ;end of display line indicator
  273. boot_area    EQU    0000h        ;setup boot area
  274. bogus_drv    EQU    0080h        ;setup bogus drive
  275. loc2        EQU    01FEh        ;last two bytes of boot sector
  276. eof_bootsec    EQU    0AA55h        ;end of boot sector (reversed)
  277. bulc        EQU    0DAh        ;box upper left corner
  278. burc        EQU    0BFh        ;box upper right corner
  279. bllc        EQU    0C0h        ;box lower left corner
  280. blrc        EQU    0D9h        ;box lower right corner
  281. bver        EQU    0B3h        ;vertical
  282. bhor        EQU    0C4h        ;horizontal
  283.  
  284.         JMP    start        ;1st byte of the sector must be a jmp
  285.         DB    'BootThru'      ;8-byte system id
  286.         DW    512        ;sector size in bytes
  287.         DB    2        ;sectors per cluster
  288.         DW    1        ;reserved clusters
  289.         DB    2        ;number of fats
  290.         DW    112        ;root directory entries
  291.         DW    720        ;total sectors
  292.         DB    0FDh        ;format id  (2 sided, 9 sector)
  293.         DW    2        ;sectors per fat
  294.         DW    9        ;sectors per track
  295.         DW    2        ;sides
  296.         DW    0        ;special hidden sectors
  297.         DB    0        ;filler
  298.         DB    0        ;head
  299.         DB    0Ah        ;length of BIOS file
  300.         DB    0DFh        ;disk parameter table
  301.         DB    02        ;      "
  302.         DB    25h        ;      "
  303.         DB    02        ;      "
  304.         DB    09        ;      "
  305.         DB    02Ah        ;Int 1Eh points to this table,
  306.         DB    0FFh        ;the disk parameter table.
  307.         DB    050h        ;contents of this vector (1Eh)
  308.         DB    0F6h        ;are used as a pointer only,
  309.         DB    0Fh        ;Int 1Eh is not executed
  310.         DB    02        ;directly
  311. intro_beg:
  312.         DB   cr,lf,
  313.         DB   cr,lf,bulc,46 DUP(bhor),burc
  314.         DB   cr,lf,bver,'      This disk was modified by BootThru      ',bver
  315.         DB   cr,lf,bver,'       Version 1.05 by Bill Gibson 1987       ',bver
  316.         DB   cr,lf,bllc,46 DUP(bhor),blrc
  317.         DB   cr,lf,stopper
  318.  
  319. intro_offset    EQU    intro_beg - head
  320.  
  321. start:
  322.         MOV    AX,07C0h    ;boot record location
  323.         MOV    ES,AX
  324.         MOV    DS,AX
  325.         MOV    SI,intro_offset
  326. strt1:
  327.         MOV    AH,0Eh            ;write teletype
  328.         MOV    AL,[SI]
  329.         CMP    AL,stopper
  330.         JE    SHORT strt2
  331.         PUSH    SI
  332.         INT    10h
  333.         POP    SI
  334.         INC    SI
  335.         JMP    SHORT strt1
  336. strt2:
  337.         CLD                ;setup to bypass drive A:
  338.         MOV    SI,OFFSET strt3 - OFFSET head
  339.         MOV    DI,0200h        ;boot sector size
  340.         MOV    CX,0200h
  341.         REPZ  MOVSB
  342.         JMP    head + 200h
  343. strt3:
  344.         MOV    AH,2        ;function 02h - read floppy disk
  345.         MOV    BX,boot_area    ;boot area
  346.         MOV    CH,0        ;track number
  347.         MOV    CL,1        ;sector
  348.         MOV    DH,0        ;head
  349.         MOV    DL,bogus_drv    ;bogus drive
  350.         MOV    AL,1        ;number of sectors
  351.         INT    13h
  352. strt4:
  353.         MOV    BX,loc2         ;setup to pull ROM Basic in
  354.         MOV    AX,[BX]         ;if an error occurs
  355.         CMP    AX,eof_bootsec
  356.         JNZ    strt9
  357.         JMP    strt3 - 200h
  358. strt9:
  359.         INT    18h
  360.  
  361.         DB    'BootThru, Copyright (c) Bill Gibson, 02.09.87'
  362. tail:
  363.  
  364. filler_amount    EQU    512 - (tail - head) - 2
  365.  
  366.         DB    filler_amount dup (0)      ; filler
  367. boot_id     DB    055h,0AAh          ; boot id
  368.  
  369. Modify        ENDP
  370.  
  371. BootThru    ENDP
  372. code        ENDS
  373.         END    BootThru
  374.